
/*******************************************************************************
 * Universidad del Valle de Guatemala
 * Algoritmos y estructuras de datos
 * Karen Tojin   08091
 * Fecha: 02 de Septiembre 2009
 * Descricion: Implementación de las colas con prioridad con uso de HEAP
 ***************************************************************************** */
/**
 *
 * @author karenAndy
 */
import java.util.PriorityQueue;
import java.util.Comparator;

public class JFCPriorityQueue<T> implements InterfacePriorityQueue {

    PriorityQueue newQueue;

    // post: constructs a new priority queue
    public JFCPriorityQueue(int size) {
        newQueue = new PriorityQueue(size, new Comparator<T>() {

            public int compare(T val1, T val2) {
                int num1 = Integer.parseInt(val1 + "");
                int num2 = Integer.parseInt(val2 + "");

                if (num1<num2) 
                    return 1;
                else if (num1>num2)
                    return -1;
                else
                    return 0;
            }
        });
    }

    // pre: value is non-null comparable
    // post: value is added to priority queue
    public void Add(Object number) {
        if (Full()) {
            System.out.println("Error! The queue is full!!");
        } else {
            newQueue.add(number);
        }
    }

    // pre: !isEmpty()
    // post: returns and removes minimum value from queue
    public T Remove() {
        return (T) newQueue.remove();
    }

    // post: returns true if no elements are in queue
    public boolean Empty() {
        return newQueue.isEmpty();
    }

    // post: returns true if the queue is full
    public boolean Full() {
        if (newQueue.size() <= 1000) {
            return false;
        } else {
            return true;
        }
    }
}
